import dayjs from "dayjs";

export const formatTime = (date: Date | string) => {
  return dayjs(date).format('YYYY-MM-DD HH:mm:ss');
};

// 获取localStorage中的数据
export const localGetItem = (key: string) => {
  const dataStr = localStorage.getItem(key);
  if (dataStr) {
    return JSON.parse(dataStr);
  }
  return null;
};

// 设置localStorage中的数据
export const localSetItem = (key: string, value: any) => {
  localStorage.setItem(key, JSON.stringify(value));
};

export const geneId = () : number => {
  return Math.floor(Math.random() * 939874);
};


export const imitateHttp = (
  fun: (s: Function, f: Function) => void,
  timer = 1000
) => {
  return new Promise((resolve, reject) => {
    setTimeout(() => fun(resolve, reject), timer);
  });
}